package booking.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import static booking.utils.Locators.*;

public class LoginPage extends BasePage {
	
	public LoginPage (WebDriver driver) {
		super(driver);
	}
	
	public ControlPanelPage loginAs (String login, String password) {
		wait.until(ExpectedConditions.visibilityOfElementLocated(inputLoginLocator));
		inputLoginElem = driver.findElement(inputLoginLocator);
		inputLoginElem.click();
		inputLoginElem.clear();
		inputLoginElem.sendKeys(login);
		
		wait.until(ExpectedConditions.visibilityOfElementLocated(inputPasswordLocator));
		inputPasswordElem = driver.findElement(inputPasswordLocator);
		inputPasswordElem.click();
		inputPasswordElem.clear();
		inputPasswordElem.sendKeys(password);
		
		wait.until(ExpectedConditions.presenceOfElementLocated(btnSubmitCredentialsLocator));
		btnSubmitCredentialsElem = driver.findElement(btnSubmitCredentialsLocator);
		wait.until(ExpectedConditions.elementToBeClickable(btnSubmitCredentialsLocator));
		btnSubmitCredentialsElem.click();
		
		return new ControlPanelPage(driver);
		
	}
	
	private WebElement inputLoginElem;
	private WebElement inputPasswordElem;
	private WebElement btnSubmitCredentialsElem;

}
